package client;


import java.util.Vector;

import client.panels.centerPanels.MeteoPanel;
import client.panels.footPanel.FootPanel;
import client.panels.headPanels.HeadPanel;
import client.stations.Station;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class MonApplication implements EntryPoint , WindowResizeListener 
{
	private DockPanel  outer = new DockPanel();
	
	private Vector stationList = new Vector();

	
	private void construireStations()
	{
		Station stat = null;
		stat	= new Station("Morillon" 	, "http://www.skiplan.com/php/genererXml.php?pays=france&region=alpes&station=morillon" );
		stationList.add(stat);
		stat	= new Station("Samoens" 	, "http://www.skiplan.com/php/genererXml.php?pays=france&region=alpes&station=samoens" );
		stationList.add(stat);
		stat	= new Station("Flaine" 		, "http://www.skiplan.com/php/genererXml.php?pays=france&region=alpes&station=flaine" );
		stationList.add(stat);
		stat	= new Station("Les Carroz" 	, "http://www.skiplan.com/php/genererXml.php?pays=france&region=alpes&station=les-carroz" );
		stationList.add(stat);
		stat	= new Station("Sixt" 		, "http://www.skiplan.com/php/genererXml.php?pays=france&region=alpes&station=sixt");
		stationList.add(stat);
	}
	
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() 
	{
		// construction des stations
		construireStations();
		
		// recup des infos des stations 
		for(int i = 0 ; i < this.stationList.size() ;  i ++ )
		{
			( (Station)this.stationList.elementAt(i) ).retrieveInfos();
		}
		
		// puis update
		new Updater(this.stationList).schedule(1000 * 9) ;
		
		HeadPanel headPanel 	=	HeadPanel.getInstance() ; headPanel.setStationLinks(this.stationList);
		FootPanel footPanel 	=	FootPanel.getInstance()	; 
		MeteoPanel meteoPanel 	=  	MeteoPanel.getInstance();
		
		
		// Hook the window resize event, so that we can adjust the UI.
		Window.addWindowResizeListener(this);

		// Get rid of scrollbars, and clear out the window's built-in margin,
		// because we want to take advantage of the entire client area.
		Window.enableScrolling(true);
		//Window.setMargin("10px");

		outer.setWidth("100%");
		outer.setHeight("100%");
		headPanel.setHorizontalAlignment(DockPanel.ALIGN_CENTER);outer.add(headPanel, DockPanel.NORTH);
		meteoPanel.setHorizontalAlignment(DockPanel.ALIGN_CENTER);;outer.add(meteoPanel, DockPanel.CENTER);
		footPanel.setHorizontalAlignment(DockPanel.ALIGN_CENTER);;outer.add(footPanel, DockPanel.SOUTH);

		RootPanel.get().add(outer);
	}

	public void onWindowResized(int width, int height) {
		// TODO Auto-generated method stub
	}
}